# 封装使用
import requests
from config.config import *
import time



def send_feishu_msg():
    message_data = [
        [
            {
                "tag": "text",
                "text": f"项目名称：{PROJECT}"
            }
        ],
        [
            {
                "tag": "text",
                "text": f"执行时间：{time.strftime('%Y-%m-%d %H:%M:%S')}"
            }
        ],
        [
            {
                "tag": "text",
                "text": "详细信息：",
            },
            {
                "tag": "a",
                "text": "查看测试报告",
                "href": REPORT_PATH
            }
        ]
    ]
    # 构建最终的消息体
    payload = {
        "msg_type": "post",
        "content": {
            "post": {
                "zh_cn": {
                    "title": "自动化测试报告",
                    "content": message_data
                }
            }
        }
    }

    if FEISHU_IS_SEND:
        # 发送消息
        response = requests.post(WEBHOOK, json=payload)
        return response


# 初始版
# import requests
# # 导入requests
#
#
# # 定义webhook地址
# webhook = "https://open.feishu.cn/open-apis/bot/v2/hook/4dd13453-6af1-424d-bb78-787ca38670c1"
#
# # 构造富文本消息
# # "tag": "text"表示文本内容
# # "tag": "a"表示超链接
# # href属性表示超链接地址
# message_data = [
#     [
#         {
#             "tag": "text",
#             "text": "星云ERP项目"
#         }
#     ],
#     [
#         {
#             "tag": "a",
#             "text": "查看测试报告",
#             "href": "https://www.baidu.com"
#         }
#     ]
# ]
#
#
# # 构建最终的消息体
# payload = {
#     "msg_type": "post",
#     "content": {
#         "post": {
#             "zh_cn": {
#                 "title": "自动化测试报告",
#                 "content": message_data
#             }
#         }
#     }
# }
#
#
# # 发送消息
# response = requests.post(webhook, json=payload)
# print(response)
# print(response.text)
